/**  
 * All rights Reserved, Designed By <a href="www.itttq.com" target="_blank">www.itttq.com</a>
 * @date:   2018-01-6 11:42:21
 * @Copyright: 2017 <a href="www.itttq.com" target="_blank">www.itttq.com</a> Inc. All rights reserved. 
 */
package com.itttq.gshop.admin.controller.pay;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.itttq.gshop.admin.controller.GenericController;
import com.itttq.gshop.domain.to.PageParamTo;
import com.itttq.gshop.domain.to.ResultPageTo;
import com.itttq.gshop.domain.po.PayLogPo;
import com.itttq.gshop.generic.connector.IPayLogConnector;

@RestController
@RequestMapping("pay/log")
public class PayLogController extends GenericController {
	private static final long serialVersionUID = 416162097981640387L;
	@Autowired
	private IPayLogConnector payLogConnector;
	
	/**
	 * 根据条件查询PayLogPo对象，并分页
	 * 
	 * @param payLog
	 * @param request
	 * @return
	 * @Author 迷蝶
	 * @return ModelAndView
	 */
	@RequestMapping("logs.html")
	public ModelAndView getPayLogs(PayLogPo payLog, HttpServletRequest request) {
		ModelAndView mv = new ModelAndView("/pay/logs");
		PageParamTo ppt = null == request ? new PageParamTo() : getPageParam(request);
		payLog.setStart(ppt.getStart());
		payLog.setSize(ppt.getSize());
		ResultPageTo<PayLogPo> rpt = payLogConnector.getPayLogs(payLog);
		this.getPageMv("logs", mv, rpt);
		mv.addObject("log", payLog);
		return mv;
	}

	
	/**
	 * 跳转到新增页面
	 * @return
	 */
	@RequestMapping("add.html")
	public ModelAndView addPayLog() {
		ModelAndView mv = new ModelAndView("/pay/logAdd");
		
		return mv;
	}
	/**
	 * 跳转到查看页面
	 * @param id
	 * @return
	 */
	@RequestMapping("view/{id}.html")
	public ModelAndView viewPayLog(@PathVariable("id") Integer id) {
		ModelAndView mv = addPayLog();
		if(id != null) {
			mv.addObject("log", payLogConnector.getPayLog(id));
		}
		mv.addObject("op", "view");
		return mv;
	}
	/**
	 * 跳转到编辑页面
	 * @param id
	 * @return
	 */
	@RequestMapping("edit/{id}.html")
	public ModelAndView editPayLog(@PathVariable("id") Integer id) {
		ModelAndView mv = viewPayLog(id);
		mv.addObject("op", "edit");
		return mv;
	}
	
	/**
	 * 保存PayLogPo对象，无ID则新增，有ID则更新
	 * 
	 * @param payLog
	 * @return
	 * @Author 迷蝶
	 * @return ModelAndView
	 */
	@RequestMapping("save.html")
	public ModelAndView savePayLog(PayLogPo payLog) {
		payLogConnector.savePayLog(payLog);
		return getPayLogs(new PayLogPo(), null);
	}

	/**
	 * 根据ID删除PayLogPo对象
	 * 
	 * @param id
	 * @return
	 * @Author 迷蝶
	 * @return ModelAndView
	 */
	@RequestMapping("del/{id}.html")
	@ResponseBody
	public ModelAndView delPayLog(@PathVariable("id") Integer id) {
		if(id != null) {
			payLogConnector.delPayLog(id);
		}
		return getPayLogs(new PayLogPo(), null);
	}
}